package com.example.android_learn;


import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import org.jsoup.Jsoup;

import java.io.IOException;

public class MainActivityViewModel extends ViewModel {
    public MutableLiveData<String> liveData = new MutableLiveData<>();

    public MutableLiveData<String> getLiveData() {

        return liveData;
    }

//    简单来说就是一个 Handler 对应一个 Looper，一个 Looper 对应一个 Message。

    public void setLiveData() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String str = "请求不到数据";
                try {
                    str = Jsoup.connect("https://www.baidu.com/").get().title();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                LiveDataUtils.setValue(liveData, str);
            }
        }).start();
    }
}
